package com.bdqn.controller;

import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * UserController
 *
 * @author LILIBO
 * @since 2023-12-08
 */
@RestController // 所有接口都将是RESTful风格的接口
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/users")
    public List<User> findAllUsers() {
        return userService.findAllUsers();
    }

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Long usrId) {
        return userService.getUser(usrId);
    }

    @PostMapping("/user")
    public void saveUser(User user) {
        userService.save(user);
    }

    @PutMapping("/user")
    public void updateUser(User user) {
        userService.updateUser(user);
    }

    @DeleteMapping("/user/{id}")
    public void deleteUser(@PathVariable("id") Long usrId) {
        userService.deleteUser(usrId);
    }

}
